﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Web.Script.Serialization;

namespace MAF.Common
{
    public class BaseUI<H, E>
        where E : IID<Guid>, new()
        where H : BaseHandler<E>
    {
        protected BaseHandler<E> _h = null;

        public BaseUI(BaseHandler<E> h)
        {
            _h = h;
        }

        public string Add()
        {
            try
            {
                _h.Add();
                return "添加成功";
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }

        public string Update()
        {
            try
            {
                _h.Update();
                return "更新成功";
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }

        public virtual string Delete()
        {
            try
            {
                int i = _h.Delete();
                return string.Format("成功删除了{0}条数据", i);
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }
    }
}